import os
from datetime import datetime

import akshare as ak
import numpy as np


def current_day():
    now = datetime.now()
    date_str = now.strftime('%Y%m%d')
    return date_str


def stock_us_indicator():
    out = "us"
    if not os.path.exists(out):
        os.makedirs(out)

    p = os.path.join(out, "us-" + current_day() + ".xlsx")

    stock_us_spot_em_df = ak.stock_us_spot_em()
    stock_us_spot_em_df["总市值"] = round(stock_us_spot_em_df["总市值"] / (10000 * 10000), 3)
    stock_us_spot_em_df.to_excel(p, sheet_name="us", index=False)


# stock_us_hist_df = ak.stock_us_hist(symbol='106.BABA', period="daily", start_date="20200101", end_date="20240812", adjust="qfq")
# stock_us_hist_df.to_excel("106.BABA.xlsx", sheet_name="us", index=False)

if __name__ == "__main__":
    stock_us_indicator()
